package com.nari.jjcall;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.nari.jjcall.util.C;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class MessageShowActivity extends ListActivity  {
	
//	private List<Map<String,TextView >> datas =  new ArrayList<Map<String,TextView>>();
	private List<Map<String,String>> datas =  new ArrayList<Map<String,String>>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		for(int i = 0 ; i < 10 ; i++){
//			Map<String,TextView> map = new HashMap<String, TextView>();
			Map<String,String> map = new HashMap<String,String>();
			TextView v = new TextView(MessageShowActivity.this);;
			if(i % 2 == 0){
				map.put("content", "000000000000000000000");
			}else {
				map.put("content", "111111111111111111111");
			}
			
			
			datas.add(map);
		}
		MessageSimpleAdapter sm = new MessageSimpleAdapter(MessageShowActivity.this, datas, R.layout.show_messages_layout, new String[]{"content"}, new int[]{R.id.message_content});
//		SimpleAdapter sm = new SimpleAdapter(MessageShowActivity.this, datas, R.layout.show_messages_layout, new String[]{"content"}, new int[]{R.id.message_content});
		setListAdapter(sm);
	}
	
	private class MessageSimpleAdapter extends SimpleAdapter{

		public MessageSimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
			super(context, data, resource, from, to);
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			
			View view = super.getView(position, convertView, parent);  
		//	View v = parent.findViewById(R.id.message_content) ;
			Log.i(C.LOG_TAG, "position:----"+position+"   view:"+view  + "   parent:"+parent);
			
			if(view != null){
				Log.i(C.LOG_TAG, "position:----"+view.getId());
				if(view.getId() == R.id.message_content){
					view.setBackgroundResource(R.drawable.my_message);
				}
//				
//				if(position % 2 ==0){
//					view.setBackgroundResource(R.drawable.my_message);
//				}else {
//					view.setBackgroundResource(R.drawable.other_message);
//				}
			}
			
//			if (v instanceof TextView) {
//				Log.i(C.LOG_TAG, "position:"+position+"   "+v  + "   "+parent);
//				//Log.i(C.LOG_TAG, tv.getText().toString());
//			} else {
//				return super.getView(position, view, parent);
//			}
			return view;
		}
	} 
}



